const { DataTypes } = require('sequelize')

module.exports = (sequelize) => {
  const Message = sequelize.define('Message', {
  id: {
    type: DataTypes.BIGINT.UNSIGNED,
    primaryKey: true,
    autoIncrement: true,
    comment: '消息ID'
  },
  userId: {
    type: DataTypes.BIGINT.UNSIGNED,
    allowNull: false,
    field: 'user_id',
    comment: '用户ID'
  },
  type: {
    type: DataTypes.ENUM('system', 'consume', 'reward', 'expire', 'activity'),
    allowNull: false,
    comment: '消息类型'
  },
  title: {
    type: DataTypes.STRING(100),
    allowNull: false,
    comment: '消息标题'
  },
  content: {
    type: DataTypes.TEXT,
    allowNull: false,
    comment: '消息内容'
  },
  extraData: {
    type: DataTypes.JSON,
    allowNull: true,
    field: 'extra_data',
    comment: '额外数据'
  },
  isRead: {
    type: DataTypes.TINYINT,
    defaultValue: 0,
    field: 'is_read',
    comment: '是否已读'
  },
  readTime: {
    type: DataTypes.DATE,
    allowNull: true,
    field: 'read_time',
    comment: '阅读时间'
  },
  createdAt: {
    type: DataTypes.DATE,
    defaultValue: DataTypes.NOW,
    field: 'created_at',
    comment: '创建时间'
  }
}, {
  tableName: 'messages',
  timestamps: false,
  comment: '消息表'
})

  return Message
}